define(function () {
    return function ($compile, $scope) {
        require(["PDAppDir/properties", "PDUtilDir/grid", "AppPathDir/video/videoInfos/support", "CkPlayer",
            "css!AppPathDir/welcome/css/welcome"], function (Properties, Grid, Support) {
            $scope.cache = {
                orgType: undefined,
                path: Properties.URL_FILE_SERVER_URL,
                playswf: getStaticPath() + "/modules/ckplayer6.7/ckplayer/ckplayer.swf",
                flashvars: {
                    f: 'http://movie.ks.js.cn/flv/other/1_0.flv',
                    c: 0,
                    e: 0,
                    h: 4,
                    my_url: encodeURIComponent(window.location.href),
                    my_title: encodeURIComponent(document.title),
                    loaded: 'loadedHandler',
                    b: 0
                },
                params: {
                    bgcolor: '#FFF',
                    allowFullScreen: true,
                    allowScriptAccess: 'always',
                    wmode: 'transparent'
                }
            };
            $scope.data = {
                products: new Array(),
                videos: new Array()
            };

            //首页数据
            $.ajax({
                url: getServer() + "/flea/hclv/video/training/selectHomeData.htmls",
                success: function (data) {
                    if (data.status != 200) {
                        return;
                    }
                    $scope.data = data.data;
                    $scope.videoSupport();
                    $scope.productSupport();
                }
            });

            //当前登录用户组织类型
            $.ajax({
                url: getServer() + "/flea/hclv/getCurrentOrgType.htmls",
                success: function (data) {
                    // console.info(data);
                    if (data.status != 200) {
                        return;
                    }

                    $scope.cache.orgType = data.data && data.data.dictCode ? data.data.dictCode : undefined;
                }
            });


            $scope.detailSupport = {
                run : function(id, name) {
                    window.top.tabs
                        .addTab({
                            id : id,
                            title : "【" + name + "】预定",
                            remote : {
                                url : getServer()
                                + "/static/core/page/home/subHome.jsp",
                                iframe : true,
                                param : {
                                    html : getServer()
                                    + "/static/app/product/searchProductInfos/views/detail.html",
                                    ctrl : getServer()
                                    + "/static/app/product/searchProductInfos/detailSupport.js",
                                    id : id
                                }
                            }
                        });
                }
            };
            //产品列表
            $scope.productSupport = function (data) {
                if ($scope.data.products.length == 0) {
                    return;
                }
                $scope.$digest();
            };
            //视频列表
            $scope.videoSupport = function (data) {
                var video = [];
                $scope.$digest();
                $.each($scope.data.videos, function (index, row) {
                    video = [$scope.cache.path + row.videoPath];
                    CKobject.embed($scope.cache.playswf, 'video_' + (index + 1), 'ckplayer_a1', '200px', '200px', true, $scope.cache.flashvars, video, $scope.cache.params);
                });
            };
        })
    }
});